
from rest_framework import serializers

from purchase_info.models import PurchaseOrderItemModel


class ChoiceGoodsSearchSerializer(serializers.Serializer):
    """
        商品选择的序列化器和反序列化
    """

    # 反序列化使用的属性：
    # write_only=True为True时字段校验时为必传参数，只允许反序列化写入做校验，不会输出
    keyword = serializers.CharField(label='货品搜索关键字，名称，件号，型号', write_only=True)

    # 序列化和反序列化都使用的属性：
    category_id = serializers.IntegerField(label='货品类别ID', required=False)
    warehouse_id = serializers.IntegerField(label='仓库ID', required=False)

    # 序列化使用的属性：
    id = serializers.IntegerField(label='货品ID', read_only=True)
    name = serializers.CharField(label='货品名称', read_only=True)
    category__name = serializers.CharField(label='货品类别名称', read_only=True)
    specification = serializers.CharField(label='货品规格/件号', read_only=True)
    model_number = serializers.CharField(label='货品型号', read_only=True)
    partner = serializers.CharField(label='厂家', read_only=True)
    units__basic_name = serializers.CharField(label='货品单位', read_only=True)
    cur_inventory = serializers.CharField(label='当前库存', read_only=True)

    class Meta:
        model = PurchaseOrderItemModel
        fields = '__all__'
